import axios from "axios";
import Vue from 'vue'

class TSys {
    constructor() {
        this.info = {
            sysTitle: "AG2022 - quash ",
            sysSubTitle: "ovr",
            copyRight: "东方科技有限公司"
        };
        this.config = {
            apiUrl: "http://127.0.0.1:42054",
            dbKey: "squ"
        }
    };

    callApi(apiPath, apiParams, method) {
        var me = this;
        return new Promise((success, fa) => {
            try {
                var url = [me.config.apiUrl, apiPath].join('/');
                var data = (apiParams && apiParams != null) ? apiParams : {};
                if (method && method == "GET") {
                    axios.get(url, data).then(res => {
                        var resData = null;
                        try {
                            resData = res.data;
                        } catch (eer) {
                            console.log(eer);
                        }
                        success(resData);
                    })
                } else {
                    axios.post(url, data).then(res => {
                        var resData = null;
                        try {
                            resData = res.data;
                        } catch (eer) {
                            console.log(eer);
                        }
                        success(resData);
                    })
                }
            } catch (error) {
                console.log(error);
                su({});
            }
        })
    };

    query(key, ps) {
        var me = this;
        var res = [];
        return new Promise((success, faild) => {
            try {
                var apiPath = "hhag/query";
                var apiParams = {
                    d: me.config.dbKey,
                    k: key,
                    p: ps || {}
                };
                me.callApi(apiPath, apiParams).then(apiRes => {
                    if (apiRes && apiRes.result) {
                        res = apiRes.result;
                    }
                    success(res);
                });
            } catch (er) {
                console.log(er);
                success(res)
            }
        })
    };
    first2Lower(str) {
        var me = this;
        var res = str;
        try {
            res = str.trim().replace(str[0], str[0].toLowerCase());
        } catch (er) {
            console.log(er)
        }
        return res;
    };
}
var sys = new TSys();

Date.prototype.Format = function(fmt) { // author: meizz 
    var o = {
        "M+": this.getMonth() + 1, // 月份 
        "d+": this.getDate(), // 日 
        "h+": this.getHours(), // 小时 
        "m+": this.getMinutes(), // 分 
        "s+": this.getSeconds(), // 秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), // 季度 
        "S": this.getMilliseconds() // 毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

Vue.prototype.sys = sys;

var feSys = new TSys();
feSys.config.apiUrl = "http://192.168.0.22:42054";
feSys.config.dbKey = "fe2023";
Vue.prototype.feSys = feSys;